﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spinning.Spinning.Unitity;
using Box2D.XNA;
using Microsoft.Xna.Framework;

namespace Spinning.Spinning.Entity.Items
{
    class Item : Actor
    {
        public Item()
        {
            Actor_Type = ActorType.Item;
            ZIndex = Constants.item;
        }

        int itemLevel = 0;

        public int ItemLevel
        {
            get;
            set;
        }

        public override void OnCreatBody(World world, Unitity.PhysicConnectManager connectManager)
        {
            BodyDef bd = new BodyDef();
            bd.type = BodyType.Static;
            body = world.CreateBody(bd);
            FixtureDef fd = new FixtureDef();
            CircleShape cs = new CircleShape();
            cs._radius = _frameSize.X / 2.45f / Constants.MeterToPixal;
            fd.shape = cs;
            _fixture = body.CreateFixture(fd);
            body.SetTransform(Vector2.Zero, 0);
            PhysicConnector connector = new PhysicConnector(this, body);
            connectManager.AddPhysicConnector(connector);

            Filter filter = new Filter();
            filter.categoryBits = (ushort)Constants.CategoryBitsItem;
            filter.maskBits = (ushort)Constants.MaskBitsItem;
            Filter = filter;
            _fixture.SetRestitution(1);
            _fixture.SetDensity(Constants.enemyDensity);
        }

        public override void BeginContact(Actor other)
        {
            base.BeginContact(other);
            if (other.Actor_Type == ActorType.Player)
            {
                SingleGamePlayer player = (SingleGamePlayer)other;
                OnTounched(player);
                //Alpha = 0;
            }
        }

        public virtual void OnTounched(SingleGamePlayer player)
        {
            player.MinusLifeTime(itemLevel);
        }

        public override void OnUpdate(GameTime gameTime)
        {
            base.OnUpdate(gameTime);
        }

    }
}
